<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{mix('/css/web/user/prove_release.css')}}">
    <script src="{{mix('/js/web/frame/jedate/jquery.jedate.js')}}"></script>
    <link rel="stylesheet" href="{{mix('/js/web/frame/jedate/skin/jedate.css')}}">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>
<body>

@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">
      @include('web.layout.seller_nav')
      <div class="right fr">
        <div class="marryreal">
          <div class="name">
            <span class="goodsfabu">@if(isset($search_params['product_type']) && $search_params['product_type']==1) 商品管理 @else 资质管理 @endif</span>
            <a href="/member/seller/product/create?step=cate"><div class="steps fabulink">发布商品</div></a>
          </div>
          <div class="marryst">
            <form action="{{URL::current()}}" method="get">
            <span>关键字</span>
            <input type="text" name="goods_name" class="ssearch" id="guanjianfont" placeholder="商品名字" value="{{ request('goods_name') }}">
            <span style="margin-left: 18px;">商品ID</span>
            <input type="text"  class="ssearch" name="goods_id" placeholder="商品ID" value="{{request('goods_id')}}">
            <span style="margin-left: 18px;">时间</span>
            <input name="updated_at[start]" class="datainp" id="inpstart" type="text" placeholder="开始日期" readonly="" value="{{array_get($search_params, 'updated_at.start')}}">
            <input name="updated_at[end]" class="datainp" id="inpend" type="text" placeholder="结束日期" readonly="" value="{{array_get($search_params, 'updated_at.end')}}">
            <span style="margin-left: 18px;">状态</span>
            <select name="is_for_sale">
              <option value="">请选择</option>
              <option value="1" @if(request('is_for_sale','') == '1') selected @endif>已上架</option>
              <option value="0"  @if(request('is_for_sale','') == '0') selected @endif>已下架</option>
              <option value="2"  @if(request('is_for_sale','') == '2') selected @endif>待审核</option>
            </select>
            <input type="submit" class="buttonn" value="查询">
            </form>
          </div>
          <div style="display:none">
          <input type="hidden" name="_scfs" value="ca350fa4d74c3b6d1640990f75488f06"/>
          </div>
          <div class="conttent">
            <div>
            <lable><input type="checkbox" name="" id="allxz">全选</lable>
            <?php if(isset($search_params['is_for_sale']) && $search_params['is_for_sale']==0){?>
                @inject('menuPresenter','App\Presenters\MenuPresenter')
                {!! $menuPresenter->renderWebOperation(10) !!}
            <?php }elseif(isset($search_params['is_for_sale']) && $search_params['is_for_sale']==1){?>
                @inject('menuPresenter','App\Presenters\MenuPresenter')
               {!! $menuPresenter->renderWebOperation(9) !!}
            <?php }else{?>
                <input type="submit" class="shelves do-curd" data-action="do-onsale" value="上架">
                <input type="submit" class="shelves do-curd" data-action="do-offsale" value="下架">
                <input type="submit" class="shelves do-curd" data-action="do-delete" value="删除">

            <?php }?>
            <span class="total">共<span class="blue">{{$page['total']}}</span>条</span>
            </div>
          </div>
          <div class="table list">
              <table>
                  <thead>
                  <tr>
                      <th width="40"></th>
                      <th width="120">图片</th>
                      <th>标题</th>
                      <th width="70">状态</th>
                      <th width="140">修改时间</th>
                      <th>操作</th>
                  </tr>
                  </thead>
                  <tbody>
                  @foreach($list as $product)
                  <tr>
                      <td><input type="checkbox" name="id[]" value="{{$product['id']}}"></td>
                      <td>
                       @if($product['product_type']== 1) 
                        <a target="_blank" href="/product/info/{{$product['id']}}/0">
                          @else
                          <a target="_blank" href="javascript:void();">
                          @endif
                          <img width="70" height="70" src="{{$product['cover_image']}}">
                        </a>
                      </td>
                      <td>
                        <span class="goodsname">
                        @if($product['product_type']== 1) 
                          <a target="_blank" href="/product/info/{{$product['id']}}/0"> {{$product['name']}} </a>
                          @else
                           <a target="_blank" href="javascript:void();"> {{$product['name']}} </a>
                          @endif
                        </span>
                        <span class="goodsid">商品ID：{{$product['id']}}</span>
                      </td>
                      <td>
                      @if($product['is_for_sale']== 1) 已上架 @else 已下架 @endif <br/>@if($product['status']!= 1) 待审核@endif</td>
                      <td>{{$product['updated_at']}}</td>
                      <td><a href="{{asset('/member/seller/product')}}/{{$product['id']}}/edit">编辑</a></td>
                  </tr>
                  @endforeach
                  </tbody>
              </table>
          </div>
            <div class="page">
                    @include('web.common.paginate', ['page' => $page])
                </div>
        </div>
      </div>
    </div>

</div>
@include('web.layout.footer')
<script type="text/javascript">
  var start = {
      format: 'YYYY-MM-DD hh:mm',
      minDate: '2014-06-16 23:59:59', //设定最小日期为当前日期
      //festival:true,
      maxDate: $.nowDate({DD:0}), //最大日期
      choosefun: function(elem,datas){
          end.minDate = datas; //开始日选好后，重置结束日的最小日期
          endDates();
      },
      okfun:function (elem,datas) {
          alert(datas)
      }
  };
  var end = {
      format: 'YYYY-MM-DD hh:mm',
      minDate: $.nowDate({DD:0}), //设定最小日期为当前日期
      //festival:true,
      maxDate: '2099-06-16 23:59:59', //最大日期
      choosefun: function(elem,datas){
          start.maxDate = datas; //将结束日的初始值设定为开始日的最大日期
      }
  };
  function endDates() {
      end.trigger = false;
      $("#inpend").jeDate(end);
  }
  $("#inpstart").jeDate(start);
  $("#inpend").jeDate(end);

  $(function(){
      //日期选择获取的值
      $(".buttonn").click(function(){
          console.log($("#guanjianfont").val());
          console.log($("#goodsid").val());
          console.log($("#inpstart").val());
          console.log($("#inpend").val());
          console.log($(".marryst select").val());
      })

      $("#allxz").click(function(){
          //全选 反选
      if (this.checked==true) {
       $(".marryreal .list  input:checkbox").prop("checked", true);
          }else{
              $(".marryreal .list  input:checkbox").prop("checked", false);
          }
       })
  })


  function doAction(params,url){
      $.ajax({
          url: url,
          type: 'post',
          dataType: 'json',
          data: params,
          success:function (data) {
              if (data.code == 0) {
                layer.alert('已提交成功',{
                    icon: 1
                },function () {
                    location.reload();
                });
              }else{
                  layer.alert('操作失败',{icon: 1});
              }
          }
      })
  }
  //上架
  $('.do-curd').click(function(){
      var ids = [];
      var url = '',param = {_token:'{{csrf_token()}}'};
      var message = '';
      $(".marryreal .list  input:checked").each(function(i,n){
         ids.push(parseInt($(n).val()))
      });
      if(ids.length == 0){
          layer.alert('请先勾选商品',{icon: 2});
          return false;
      }
      param.ids = ids;
      switch($(this).data('action')){
          case 'do-delete':
              url = "{{url('/member/seller/product/batchdel')}}";
              message = '删除';
              break;
          case 'do-onsale':
              url ="{{url('/member/seller/product/batchsale')}}";
              message = '上架';
              param.is_sale = 1;
              break;
          case 'do-offsale':
        	  url ="{{url('/member/seller/product/batchsale')}}";
              message = '下架';
              param.is_sale = 0;
              break;
      }

      // 增加操作前提示
      layer.alert('确认'+message+'该商品吗？',{
          icon: 1
      },function (index) {
          doAction(param,url);
      });
  });
</script>
</body>
</html>